;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")

;; ((c++-mode
;;   ;; (flycheck-gcc-language-standard . "gnu99")
;;   (ps-landscape-mode . t)
;;   (ps-paper-type . "letter")
;;   (ps-number-of-columns . 2)
;;   (;; Hard-wrap text automatically
;;    auto-fill-mode . t)
;;   (;; At what column to start right-aligned comments
;;    comment-column . 30)
;;   (;; Column to use for ‘comment-indent’.  If nil, use ‘fill-column’ instead.
;;    comment-fill-column . nil)
;;   (;; Tell at what column to wrap left-aligned text
;;    fill-column . 50)
;;
;;   ;; (flycheck-clang-language-standard . "gnu99")
;;   )
;;
;;  ("src" . ((nil
;;             .
;;             (
;;              (ps-landscape-mode . t)
;;              (ps-paper-type . "letter")
;;              (ps-number-of-columns . 2)
;;              (comment-column . 50)
;;              (comment-fill-column . 50)
;;              (fill-column . 50)
;;
;;              (compile-command . "if [ ! -d ../build ]; then mkdir ../build; fi; cd ../build && cmake .. && make")))))
;;
;;  )

;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
(
 ;; Default variables for all directories and modes
 (nil
  .
  (
   ;; (eval              ;https://emacs.stackexchange.com/a/35965
   ;;  . (progn
   ;;      (with-temp-buffer           ;https://stackoverflow.com/a/16789182
   ;;        (call-process "bash" nil t nil "-c"
   ;;                      "source /opt/moose/environments/moose_profile; env")
   ;;        (goto-char (point-min))
   ;;        (while (not (eobp))
   ;;          (setq process-environment
   ;;                (cons (buffer-substring (point) (line-end-position))
   ;;                      process-environment))
   ;;          (forward-line 1)))
   ;;      ;; (setenv "METHOD" "dbg")
   ;;      ))
   ))

 ;; Default variables for C mode in all directories
 (c-mode
  .
  ((mode                                ;https://stackoverflow.com/a/6912415
    .
    c++)

   (compile-command
    .
    (concat
     "source /opt/moose/environments/moose_profile && "
     "export CC=clang CXX=clang++ OMPI_MPICC=clang OMPI_CXX=clang++ LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 && make -j $MOOSE_JOBS -C ../; "
     ;; "LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 METHOD=dbg make -j $MOOSE_JOBS -C ../"
     ))
   ))

 ;; Default variables for C++ mode in all directories
 (c++-mode
  .
  ((compile-command
    .
    (concat
     "source /opt/moose/environments/moose_profile && "
     "export CC=clang CXX=clang++ OMPI_MPICC=clang OMPI_CXX=clang++ LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 && make -j $MOOSE_JOBS -C ../; "
     ;; "LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 METHOD=dbg make -j $MOOSE_JOBS -C ../"
     ))
   ))

 ;; Default variables for GetPot mode in all directories
 (getpot-mode
  .
  ((compile-command
    .
    (concat
     "source /opt/moose/environments/moose_profile && "
     ;; "mpirun -np $(lscpu | awk '/^CPU\\(s\\)/{print $2}')" ; set mpirun with max cpus
     "LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 mpirun -np $MOOSE_JOBS"     ; set mpirun with max cpus
     " ../spider-opt -i "         ;executable to use
     (if buffer-file-name
         (shell-quote-argument
          (buffer-file-name)))))))

 ;; Default variables for Gmsh mode in all directories
 (gmsh-mode
  .
  ((compile-command
    .
    (concat "gmsh -optimize_ho -format msh -3 -o "
            (if buffer-file-name
                (shell-quote-argument
                 (file-name-sans-extension buffer-file-name)))
            ".msh "
            (if buffer-file-name
                (shell-quote-argument
                 (buffer-file-name)))
            ))))
 )
